//
//  APPointmentHospitalViewController.m
//  XDBaseFrameWork
//
//  Created by XD-XY on 9/26/14.
//  Copyright (c) 2014 XD-XY. All rights reserved.
//

#import "APPointmentHospitalViewController.h"

#import "ChooseCameraManViewController.h"
#import "OrderConfirmViewController.h"
#import "loginViewController.h"
#import "ZhiFuTypeCell.h"
//支付宝客户端头文件
#import "DataSigner.h"
#import "AlixPayResult.h"
#import "DataVerifier.h"
#import "AlixPayOrder.h"
#import "PartnerConfig.h"
#import "AlixLibService.h"

#import "PayByBagViewController.h"

@interface APPointmentHospitalViewController ()
{
    BOOL chooseZhiFuType;
    NSString * priceString;
    UILabel * yifuLB;
    UIWebView * malongWeb;
    UIButton * downBtn;
}
@end

@implementation APPointmentHospitalViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
//    locService.delegate = self;
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
//    locService.delegate = nil;
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    if (![[NSUserDefaults standardUserDefaults] valueForKey:@"chushengzhaocommand"]){
        [self performSelector:@selector(showRecommand) withObject:nil afterDelay:0.25];
        
    }
}

-(void)backPrePage
{
    [XDTools sharedXDTools].hospitalVC = nil;
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.titleLabel.text = @"预约摄影";
    priceString = [[NSString alloc] init];
    
    chooseZhiFuType = NO;
    [XDTools sharedXDTools].hospitalVC = self;
    [XDTools sharedXDTools].orderDetailVC = nil;           //订单详情
    [XDTools sharedXDTools].chooseImageVC = nil;           //选片页面
    [XDTools sharedXDTools].OrderConfirmVC = nil;         //订单确认页
    isFirst = YES;
    emplTimeArray = [[NSMutableArray alloc] init];
    orderID = [[NSMutableString alloc] init];
    
    
    
    UIButton * helpBtn = [self createButtonOnNavigationWithRect:CGRectMake(UI_SCREEN_WIDTH-50, 0, 50, 44) normalImg:LOADIMAGE(@"i4@2x") highlightImg:LOADIMAGE(@"i4@2x")];
    [helpBtn addTarget:self action:@selector(showRecommand) forControlEvents:UIControlEventTouchUpInside];
    [self.navigationBarView addSubview:helpBtn];
    
    [self initViews];
    
    malongWeb = [[UIWebView alloc] init];
    malongWeb.frame = CGRectMake(0, self.view.frame.size.height,self.view.frame.size.width, self.view.frame.size.height);
    malongWeb.backgroundColor = mClearColor;
    NSString * s = @"http://123.57.16.119/index.php?m=Api&c=Index&a=intro";
    [malongWeb loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:s]]];
    malongWeb.hidden = YES;
    malongWeb.scrollView.delegate = self;
    [self.view addSubview:malongWeb];
    
    CGFloat dheight = IOS7?20:0;
    downBtn = [UIButton initButton:CGRectMake(UI_SCREEN_WIDTH-42, dheight+20,32,32) btnImage:LOADIMAGE(@"wcha@2x") btnTitle:nil];
    [downBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    downBtn.backgroundColor = [UIColor clearColor];
    [downBtn addTarget:self action:@selector(downRecommend) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:downBtn];
    downBtn.hidden = YES;
    
    timeView = [[TimeView alloc] initWithFrame:self.contentView.frame];
    [timeView setSouceTime:3];  //1表示是到家
    timeView.delegate  =self;
    [self.view addSubview:timeView];
//
//    [self getDingWeiInfo];  //获取定位信息
    
    hospitalLB.text = [self.hostpitalArray firstObject][@"PMName"];
    self.pmid = [self.hostpitalArray firstObject][@"PMID"];
//    if (self.type == 1){
//        latitude = [[self.hostpitalArray firstObject][@"PosE"] floatValue];
//        longitude = [[self.hostpitalArray firstObject][@"PosN"] floatValue];
//    }
    textView.text = [self.hostpitalArray firstObject][@"PMDesc"];
    
    [self getCSPrice];
    mScrollView.hidden = YES;
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{

    if (scrollView == malongWeb.scrollView){
        if(malongWeb.scrollView.contentSize.height-malongWeb.scrollView.contentOffset.y<UI_SCREEN_HEIGHT-150){
            [self downRecommend];
        }
    }
    
}

#pragma mark  显示介绍
-(void)showRecommand
{
    malongWeb.hidden = NO;
    [UIView animateWithDuration:0.45 animations:^{
        malongWeb.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    } completion:^(BOOL finished) {
        downBtn.hidden = NO;
    }];
}

#pragma mark 取消介绍
-(void)downRecommend
{
    downBtn.hidden = YES;
    [UIView animateWithDuration:0.45 animations:^{
        malongWeb.frame = CGRectMake(0,self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height);
    } completion:^(BOOL finished) {
        malongWeb.hidden = NO;
    }];
    [[NSUserDefaults standardUserDefaults] setValue:@"1" forKey:@"chushengzhaocommand"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

#pragma mark
#pragma mark UI 布局
-(void)initViews
{
    mScrollView = [[UIScrollView alloc] initWithFrame:self.contentView.bounds];
    mScrollView.contentSize = CGSizeMake(320, self.contentView.frame.size.height);
    mScrollView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:mScrollView];
    
    
    UIImageView * hostpitalIV = [UIImageView initImageViewRect:CGRectMake(20, 15, 280, 40) andImage:LOADIMAGE(@"inputadress@2x") andUserInteractionEnabled:YES];
    [mScrollView addSubview:hostpitalIV];
    
    UIImageView * timeIV = [UIImageView initImageViewRect:CGRectMake(20,height_y(hostpitalIV)+15, 280, 40) andImage:LOADIMAGE(@"inputtime@2x") andUserInteractionEnabled:YES];
    [mScrollView addSubview:timeIV];
    
    hospitalLB = [UILabel initLabelText:@"请选择医院" andRect:CGRectMake(61,0,200,40) andBackGroudColor:mClearColor andTextFont:[UIFont systemFontOfSize:14.5] andTextColor:UIColorFromRGB(0x666666) andTextAlignment:NSTextAlignmentLeft];
    hospitalLB.userInteractionEnabled = YES;
    [hostpitalIV addSubview:hospitalLB];
    
    UIImageView * arrowIV = [[UIImageView alloc] initWithFrame:CGRectMake(195, 13.5f, 7.5f, 12.5f)];
    arrowIV.image = [UIImage imageNamed:@"arrow_cell"];
    [hospitalLB addSubview:arrowIV];
    
    timeLB = [UILabel initLabelText:@"请选择预约时间" andRect:CGRectMake(61,0,200,40) andBackGroudColor:mClearColor andTextFont:[UIFont systemFontOfSize:14.5] andTextColor:UIColorFromRGB(0x666666) andTextAlignment:NSTextAlignmentLeft];
    timeLB.userInteractionEnabled = YES;
    [timeIV addSubview:timeLB];
    
    
//    UIView * textbgView = [UIView initViewRect:CGRectMake(20, height_y(timeIV)+20, 280, 200) andBackGroudColor:[UIColor clearColor]];
//    textbgView.layer.cornerRadius = 5;
//    textbgView.layer.masksToBounds = YES;
//    textbgView.layer.borderWidth = 1;
//    textbgView.layer.borderColor =[UIColorFromRGB(0xd4ccc5) CGColor];
//    [mScrollView addSubview:textbgView];
//    
//    textView = [[UITextView alloc] initWithFrame:CGRectMake(10, 10, 260, 180)];
//    textView.font = [UIFont systemFontOfSize:14.5];
//    textView.textColor = UIColorFromRGB(0x6f6254);
//    textView.backgroundColor = [UIColor clearColor];
//    textView.editable = NO;
//    [textbgView addSubview:textView];
    
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(chooseHospital)];
    [hospitalLB addGestureRecognizer:tap];
    
    UITapGestureRecognizer * tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(chooseTime)];
    [timeLB addGestureRecognizer:tap2];
    
    UIView * footview = [UIView initViewRect:CGRectMake(0, self.view.frame.size.height-163/2.0f, UI_SCREEN_WIDTH, 81.5) andBackGroudColor:[UIColor whiteColor]];
    footview.tag= 1144;
    [self.view addSubview:footview];
    footview.hidden = YES;
    
    UIView * line = [UIView initViewRect:CGRectMake(0, 0.5, UI_SCREEN_WIDTH, 0.5) andBackGroudColor:UIColorFromRGB(0xd4ccc5)];
    [footview addSubview:line];
    
    UIButton * suerOrChooseBtn = [UIButton initButton:CGRectMake(45,21, 230, 40) btnImage:LOADIMAGE(@"xiadan@2x") btnTitle:@"确认下单" titleColor:[UIColor whiteColor] titleFont:[UIFont systemFontOfSize:16]];
    [suerOrChooseBtn addTarget:self action:@selector(suerOrchooseempl) forControlEvents:UIControlEventTouchUpInside];
    [footview addSubview:suerOrChooseBtn];
    
    yifuLB = [UILabel initLabelText:@"" andRect:CGRectMake(0,height_y(timeIV)+20,UI_SCREEN_WIDTH,20) andBackGroudColor:mClearColor andTextFont:[UIFont systemFontOfSize:18] andTextColor:UIColorFromRGB(0x434343) andTextAlignment:NSTextAlignmentCenter];
    [mScrollView addSubview:yifuLB];

    
    //选择支付方式
    UILabel * l = [UILabel initLabelText:@"选择支付方式" andRect:CGRectMake(8,height_y(yifuLB)+15,200,15) andBackGroudColor:mClearColor andTextFont:[UIFont systemFontOfSize:15] andTextColor:UIColorFromRGB(0x888888) andTextAlignment:NSTextAlignmentLeft];
    [mScrollView addSubview:l];
    
    UITableView * mTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, height_y(l)+8, UI_SCREEN_WIDTH, 100) style:UITableViewStylePlain];
    mTableView.backgroundColor = mClearColor;
    mTableView.delegate =self;
    mTableView.dataSource= self;
    mTableView.bounces = NO;
    mTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [mScrollView addSubview:mTableView];
}

#pragma mark 
#pragma mark 选择医院
-(void)chooseHospital
{
    ChooseHospitalViewController * cvc = [[ChooseHospitalViewController alloc] init];
    cvc.delegate = self;
    cvc.dataArray = self.hostpitalArray;
    [self.navigationController pushViewController:cvc animated:YES];
}

#pragma mark
#pragma mark 选择时间
-(void)chooseTime
{
    [timeView setSouceTime:3];

    [timeView setTheViewShow];
}

#pragma mark
#pragma mark 下单或选择摄影师
-(void)suerOrchooseempl
{
    if ([hospitalLB.text isEqualToString:@"请选择医院"]){
        [XDTools showTips:@"请选择医院" toView:self.view];
        return;
    }
    if ([timeLB.text isEqualToString:@"请选择预约时间"]){
        [XDTools showTips:@"请选择预约时间" toView:self.view];
        return;
    }
    
    if (!ISLOGING){
        loginViewController * loginVC = [[loginViewController alloc] init];
        [self.navigationController pushViewController:loginVC animated:YES];
    }else{
        [XDTools sharedXDTools].iphoneNumber = [[NSUserDefaults standardUserDefaults] valueForKey:kMY_USER_IPHONE];
        //时间
        [XDTools sharedXDTools].time = timeLB.text;
                
        [XDTools sharedXDTools].CustomerID = [[NSUserDefaults standardUserDefaults] objectForKey:kMY_USER_ID];
        
        [XDTools sharedXDTools].SeriesID = self.SeriesID;
        [XDTools sharedXDTools].CityID = BJcityID;
        [XDTools sharedXDTools].ShootAddr =hospitalLB.text;
        [XDTools sharedXDTools].ModeID = self.pmid;
        [self uploadOrdersInfo];
    }
}

#pragma mark
#pragma mark ChooseHospitalViewController Delegate
-(void)chooseHospitalInfo:(NSDictionary *)dict
{
    hospitalLB.text = dict[@"PMName"];
    self.pmid = dict[@"PMID"];
    textView.text = dict[@"PMDesc"];
}

#pragma mark
#pragma mark TimeViewDelegate
-(void)chooseTimeWithDay:(NSString *)mDay hour:(NSString *)mHour second:(NSString *)mSecond
{

    NSString * s = [[mHour componentsSeparatedByString:@"点"] firstObject];
    NSString * s2 = [[mSecond componentsSeparatedByString:@"分"] firstObject];
    timeLB.text = [NSString stringWithFormat:@"%@ %@:%@",mDay,s,s2];

    day = [[NSString alloc] initWithFormat:@"%@",mDay];
    hour = [[NSString alloc] initWithFormat:@"%@",mHour];
    
}

#pragma mark
#pragma mark 定位
-(void)getDingWeiInfo
{
    if([XDTools sharedXDTools].longitude&&[XDTools sharedXDTools].latitude){
        locService = [[BMKLocationService alloc] init];
        locService.delegate  =self;
        [locService startUserLocationService];
    }else{
        [XDTools showTips:@"请在隐私中打开定位服务" toView:self.view];
    }
}

#pragma mark
#pragma mark 百度地图定位
/**
 *在停止定位后，会调用此函数
 */
- (void)didStopLocatingUser
{
    NSLog(@"停止定位");
}

/**
 *用户方向更新后，会调用此函数
 *@param userLocation 新的用户位置
 */
- (void)didUpdateUserHeading:(BMKUserLocation *)userLocation
{
    if (!self.type){
        latitude = userLocation.location.coordinate.latitude;
        longitude = userLocation.location.coordinate.longitude;
    }
    if (latitude>0&&longitude>0){
        [locService stopUserLocationService];
        [XDTools sharedXDTools].latitude = latitude;
        [XDTools sharedXDTools].longitude = longitude;
    }
}

/**
 *用户位置更新后，会调用此函数
 *@param userLocation 新的用户位置
 */
- (void)didUpdateUserLocation:(BMKUserLocation *)userLocation
{
    if (!self.type){
        latitude = userLocation.location.coordinate.latitude;
        longitude = userLocation.location.coordinate.longitude;
    }
    if (latitude>0&&longitude>0){
        [locService stopUserLocationService];
        [XDTools sharedXDTools].latitude = latitude;    //经度
        [XDTools sharedXDTools].longitude = longitude;  //纬度
    }
}

/**
 *定位失败后，会调用此函数
 *@param mapView 地图View
 *@param error 错误号，参考CLError.h中定义的错误号
 */
- (void)mapView:(BMKMapView *)mapView didFailToLocateUserWithError:(NSError *)error
{
    NSLog(@"location error");
}

#pragma mark
#pragma mark 获取摄影师时间
-(void)getEmplTime
{
    if (![XDTools NetworkReachable]){
        [XDTools showTips:brokenNetwork toView:self.view];
        return;
    }
    ASIHTTPRequest * request = [XDTools postRequestWithDict:@{@"EmplID":self.empID} API:API_getEmplTime];
    __weak ASIHTTPRequest * mrequest = request;
    [request setCompletionBlock:^{
        [XDTools hideProgress:self.contentView];
        NSDictionary * tmpDict = [XDTools JSonFromString:[mrequest responseString]];
        if ([tmpDict[@"status"] intValue]==1){
            [emplTimeArray removeAllObjects];
            if (ARRAY_IS_NOT_EMPTY(tmpDict[@"data"][@"EmplUsedTime"])){
                [emplTimeArray addObjectsFromArray:tmpDict[@"data"][@"EmplUsedTime"]];
            }
        }else{
            [XDTools showTips:tmpDict[@"msg"] toView:self.view];
        }
    }];
    [request setFailedBlock:^{
        [XDTools hideProgress:self.view];
        [XDTools showTips:networkovertime toView:self.view];
    }];
    [request startAsynchronous];
    [XDTools showProgress:self.contentView];
}


#pragma mark
#pragma mark UITableView Delegate
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * cellName = @"cell";
    ZhiFuTypeCell * cell = [tableView dequeueReusableCellWithIdentifier:cellName];
    if (cell == nil){
        cell = [[ZhiFuTypeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    if (indexPath.row == 0){
        cell.zhifuiconIV.image = LOADIMAGE(@"alipayClientIcon@2x");
        cell.titleLB.text = @"支付宝客户端支付";
        cell.contentLB.text = @"推荐已安装支付宝客户端的用户使用";
        if (chooseZhiFuType){
            cell.chooseBtn.enabled = YES;
        }else{
            cell.chooseBtn.enabled =NO;
        }
        cell.downline.hidden = NO;
    }else{
        cell.zhifuiconIV.image = LOADIMAGE(@"alipayWapIcon@2x");
        cell.titleLB.text = @"支付宝网页支付";
        cell.contentLB.text = @"推荐有支付宝账号的用户使用";
        if (chooseZhiFuType){
            cell.chooseBtn.enabled = NO;
        }else{
            cell.chooseBtn.enabled =YES;
        }
        cell.downline.hidden = YES;
    }
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row){
        chooseZhiFuType = YES;
    }else{
        chooseZhiFuType = NO;
    }
    [tableView reloadData];
}


#pragma mark
#pragma mark 提交订单
-(void)uploadOrdersInfo
{
    if (![XDTools NetworkReachable]){
        mScrollView.hidden = NO;
        [XDTools showTips:brokenNetwork toView:self.view];
        return;
    }
    if(!isFirst){
        if(chooseZhiFuType){  //网页支付
            [self payByWeb];
        }else{  //客户端支付
            [self payByKeHuDuan];
        }
        return;
    }
    NSDictionary * parms = @{@"SceneID":self.SceneID,
                             @"CustomerID":[XDTools sharedXDTools].CustomerID,
                             @"CityID":BJcityID,
                             @"ShootDate":timeLB.text,
                             @"ShootAddr":hospitalLB.text,
                             @"ModeID":self.pmid
                             };
    ASIHTTPRequest * request = [XDTools postRequestWithDict:parms API:api_addCXOrder];
    __weak ASIHTTPRequest * mrequest = request;
    [request setCompletionBlock:^{
        [XDTools hideProgress:self.contentView];
        NSDictionary * tmpDict = [XDTools JSonFromString:[mrequest responseString]];
        if ([tmpDict[@"status"] intValue]==1){
            mScrollView.hidden = NO;
            orderID = tmpDict[@"data"][@"OrderID"];
            isFirst = NO;
            if(chooseZhiFuType){  //网页支付
                [self payByWeb];
            }else{  //客户端支付
                [self payByKeHuDuan];
            }

        }else{
            mScrollView.hidden = YES;
            [XDTools showTips:tmpDict[@"msg"] toView:self.view];
        }
    }];
    [request setFailedBlock:^{
        mScrollView.hidden = YES;
        [XDTools hideProgress:self.view];
        [XDTools showTips:networkovertime toView:self.view];
    }];
    [request startAsynchronous];
    [XDTools showProgress:self.contentView];
}

#pragma mark
#pragma mark 出生照价格
-(void)getCSPrice
{
    if (![XDTools NetworkReachable]){
        mScrollView.hidden = YES;
        UIView * footview = [self.view viewWithTag:1144];
        footview.hidden = YES;
        [XDTools showTips:brokenNetwork toView:self.view];
        return;
    }
    if(!isFirst){
        if(chooseZhiFuType){  //网页支付
            [self payByWeb];
        }else{  //客户端支付
            [self payByKeHuDuan];
        }
        return;
    }

    ASIHTTPRequest * request = [XDTools postRequestWithDict:@{} API:API_CSPrice];
    __weak ASIHTTPRequest * mrequest = request;
    [request setCompletionBlock:^{
        [XDTools hideProgress:self.contentView];
        NSDictionary * tmpDict = [XDTools JSonFromString:[mrequest responseString]];
        if ([tmpDict[@"status"] intValue]==1){
            mScrollView.hidden = NO;
            UIView * footview = [self.view viewWithTag:1144];
            footview.hidden = NO;
            
            priceString = tmpDict[@"data"][@"Price"];
            
            yifuLB.text = [NSString stringWithFormat:@"应付金额：￥%@",priceString];
            yifuLB.attributedText = [XDTools getAcolorfulStringWithTextArray:@[[NSString stringWithFormat:@"￥%@",priceString]] Color:RGBA(255, 116, 106, 1) Font:[UIFont systemFontOfSize:18] AllText:yifuLB.text];
        }else{
            if (IS_NOT_EMPTY(tmpDict[@"data"][@"msg"])){
                [XDTools showTips:tmpDict[@"data"][@"msg"] toView:self.view];
            }
            mScrollView.hidden = NO;
            UIView * footview = [self.view viewWithTag:1144];
            footview.hidden = NO;
        }
    }];
    [request setFailedBlock:^{
        [XDTools hideProgress:self.contentView];
        mScrollView.hidden = YES;
        UIView * footview = [self.view viewWithTag:1144];
        footview.hidden = YES;
        [XDTools showTips:networkovertime toView:self.view];
    }];
    [request startAsynchronous];
    [XDTools showProgress:self.contentView];
}

#pragma mark
#pragma mark 支付

//通过网页支付
-(void)payByWeb
{
    NSString * str0 = [NSString stringWithFormat:@"http://123.57.16.119/index.php?m=Api&c=WapAlipay&a=doalipay&out_trade_no=%@&subject=%@&total_fee=%@",orderID,@"出生照",priceString];
    NSString * payURL = [str0 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *malongUrl = [NSURL URLWithString:payURL];
    
    PayByBagViewController *payVC = [[PayByBagViewController alloc] init];
    payVC.webUrl = malongUrl;
    [self.navigationController pushViewController:payVC animated:YES];
    
}

-(void)payByKeHuDuan //客户端支付
{
    BOOL yy =  [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"alipay://"]];
    
    if (!yy) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"支付提示" message:@"支付失败，检测到您的设备没有安装支付宝，请选择其他支付方式" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        
        [alert show];
        
        return;
    }
    
    NSString *appScheme = @"com.xindao.meishimeike";
    NSString* orderInfo = [self getOrderInfo];
    NSString* signedStr = [self doRsa:orderInfo];
    
    NSString *orderString = [NSString stringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"",
                             orderInfo, signedStr, @"RSA"];
    NSLog(@"orderString:%@",orderString);
    
    [AlixLibService payOrder:orderString AndScheme:appScheme seletor:sel target:self];
}

//支付宝回调
-(void)paymentResultDelegate:(NSString *)result{
    
}

-(void)paymentResult:(NSString *)result{
    
}

-(NSString*)getOrderInfo
{
    
    //拼接商品信息
    AlixPayOrder *order = [[AlixPayOrder alloc] init];
    order.partner = PartnerID;
    order.seller = SellerID;
    
    
    NSString *desc = [XDTools sharedXDTools].taocanDesc;
    
    desc = @"出生照";
    
    order.productName = @"出生照";
    order.tradeNO = orderID;  //订单ID（由商家自行制定）   ///需要赋值
    order.productDescription = desc;
    order.amount = priceString; //商品价格
    
    order.notifyURL = @"http://123.57.16.119/call_back.php";
    
	return [order description];
}

-(NSString*)doRsa:(NSString*)orderInfo
{
    id<DataSigner> signer;
    signer = CreateRSADataSigner(PartnerPrivKey);
    NSString *signedString = [signer signString:orderInfo];
    return signedString;
}

//////支付成功后跳入
//-(void)refreshOrderConfirmStatus{
//    OrderSuccessViewController * success = [[OrderSuccessViewController alloc] init];
//    [self.navigationController pushViewController:success animated:YES];
//}

//进入订单列表
- (void)goToOrderList{
    [self.navigationController popToRootViewControllerAnimated:YES];
    [[XDTools appDelegate].tabBarController confirmSelectTabBar:1];
    [[XDTools appDelegate].tabBarController setSelectedIndex:1];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
